<!-- PAGE CONTENT WRAPPER -->
<div class="page-content-wrap">
    <div class="row">
        <div class="col-md-12">

            <form class="form-horizontal">
                <div class="panel panel-default">
                    <input name="go" value="${param.go}" type="hidden">
                    <div class="panel-heading">
                        <h3 class="panel-title" id="title"></h3>
                        <ul class="panel-controls">
                            <li><a href="javascript:window.location.href=document.referrer;"><i class="fa fa-arrow-left"></i></a></li>
                        </ul>
                    </div>
                    <div class="panel-body">
                        <p>在这里新增或者修改一个报修订单。</p>
                    </div>

                    <input type="hidden" id="repairOrderId" value="${repairOrder.id}">

                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="col-md-3 control-label">报修人姓名</label>

                                    <div class="col-md-9">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span class="fa fa-pencil"></span></span>
                                            <input type="text" class="form-control" id="connectionUserName"
                                                   value="${repairOrder.connectionUserName}"/>
                                        </div>
                                        <div id="connectionUserNameValid"></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">报修人手机号</label>

                                    <div class="col-md-9">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span class="fa fa-pencil"></span></span>
                                            <input type="text" class="form-control" id="connectionUserMobile"
                                                   value="${repairOrder.connectionUserMobile}"/>
                                        </div>
                                        <div id="connectionUserMobileValid"></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">报修人地址</label>

                                    <div class="col-md-9">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span class="fa fa-pencil"></span></span>
                                            <input type="text" class="form-control" id="connectionUserAddress"
                                                   value="${repairOrder.connectionUserAddress}"/>
                                        </div>
                                        <div id="connectionUserAddressValid"></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">维修分类</label>

                                    <div class="col-md-9">
                                        <select class="form-control select" id="categoryId">
                                            <c:forEach var="par" items="${categoryRepository.findByParentId(0)}">
                                                <option value="${par.id}"
                                                        <c:if test="${repairOrder.categoryId==par.id}">selected</c:if>>${par.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">选择师傅</label>

                                    <div class="col-md-9">
                                        <select class="form-control select" id="repairPersonId">
                                            <c:forEach var="par" items="${repairPersonRepository.findAll()}">
                                                <option value="${par.id}"
                                                        <c:if test="${repairOrder.repairPersonId==par.id}">selected</c:if>>${par.name}&nbsp;&nbsp;${par.mobile}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">报修内容</label>

                                    <div class="col-md-9">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span class="fa fa-pencil"></span></span>
                                            <input type="text" class="form-control" id="content"
                                                   value="${repairOrder.content}"/>
                                        </div>
                                        <div id="contentValid"></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">备注</label>

                                    <div class="col-md-9">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span class="fa fa-pencil"></span></span>
                                            <input type="text" class="form-control" id="remark"
                                                   value="${repairOrder.remark}"/>
                                        </div>
                                        <div id="remarkValid"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="panel-footer">
                            <span class="btn btn-primary pull-right" onclick="submita()">保存</span>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>

</div>
<!-- END PAGE CONTENT WRAPPER -->
<script>
    var repairOrderId;
    function submita() {
        var param = {};
        param.id = repairOrderId == '' ? -1 : repairOrderId;
        param.connectionUserName = $('#connectionUserName').val();
        param.connectionUserMobile = $('#connectionUserMobile').val();
        param.connectionUserAddress = $('#connectionUserAddress').val();
        param.categoryId = $('#categoryId').val();
        param.repairPersonId = $('#repairPersonId').val();
        param.remark = $('#remark').val();
        param.content = $('#content').val();
        param.admin = "-1";

        if (!param.connectionUserName || param.connectionUserName == '') {
            var vhtml = '<label id="re-password-error" class="error" for="re-password">请输入报修人姓名！</label>';
            $('#connectionUserNameValid').html(vhtml);
            return false;
        }
        if (!param.connectionUserMobile || param.connectionUserMobile == '') {
            var vhtml = '<label id="re-password-error" class="error" for="re-password">请输入报修人手机号！</label>';
            $('#connectionUserMobileValid').html(vhtml);
            return false;
        }
        if (!param.connectionUserAddress || param.connectionUserAddress == '') {
            var vhtml = '<label id="re-password-error" class="error" for="re-password">请输入报修人地址！</label>';
            $('#connectionUserAddressValid').html(vhtml);
            return false;
        }

        json("/admin/repair/saveRepairOrder.jspx", {param: JSON.stringify(param)}, function (data) {
            window.location.href = document.referrer;
        });
    }
    function submitb() {
        setTimeout(function () {
            submita();
        }, 100);
    }

    $(function () {
        repairOrderId = $('#repairOrderId').val();
        $('#title').html(repairOrderId == '' ? '添加报修订单' : '修改报修订单');
    });
</script>
